<template>
  <div class="goods-list">
    <div class="goods-item" v-for="item in goodsList" :key="item.id">
      <router-link to="/home/goodsInfo"><img :src="item.img_url" alt /></router-link>
      <h1 class="title">{{item.title}}</h1>
      <div class="info">
        <p class="price">
          <span class="now">＄{{item.sell_price}}</span>
          <span class="old">＄{{item.market_price}}</span>
        </p>
        <p class="sell">
          <span>热卖中</span>
          <span>剩余{{item.stock_quantity}}件</span>
        </p>
      </div>
    </div>
  </div>
</template>

<script>
export default{
  created(){
    this.getGoodsList();
  },
  data(){
    //是往自己组建的内部关在一些私有的数据
    return{
      goodsList:[]
    }
  },
  methods:{
    //获取商品列表
    getGoodsList(){
      this.$http.get("http://www.liulongbin.top:3005/api/getgoods").then(result=>{
        if(result.body.status == 0){
          this.goodsList = result.body.message;
        }
      })
    }
  }
};
</script>

<style lang="stylus" scoped>
.goods-list {
  display: flex;
  flex-wrap: wrap;
  justify-content :space-between;
  padding :2px;
}

.goods-item {
  border:1px solid #ccc;
  box-shadow :0 0 0px #ccc;
  width: 49%;
  padding :2px;
  
  img {
    width:100%;
  }
  .title{
    font-size :14px;
  }
  .info{
    background-color : #eee;
    p {
      margin :0;
      padding: 5px;
    }
    .price{
      color :red;
      font-weight :bold;
      font-size :16px;

    }
    .old{
      text-decoration :line-through;
    }
    .sell{
      display:flex;
      justify-content :space-between;
      font-size 12px;
    }
  }
}
</style>